package com.wingscode.modules.sys.controller;

import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.R;
import com.wingscode.modules.sys.entity.BuildQualEntity;
import com.wingscode.modules.sys.entity.InquiryEntity;
import com.wingscode.modules.sys.entity.InquiryLinkEntity;
import com.wingscode.modules.sys.entity.OfferPriceEntity;
import com.wingscode.modules.sys.service.InquiryLinkService;
import com.wingscode.modules.sys.service.InquiryService;
import com.wingscode.modules.sys.service.OfferPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 市场管理
 *
 * @author yan
 */
@RestController
@RequestMapping("/market")
public class MarketController extends AbstractController {
	@Autowired
	private InquiryService inquiryService;
	@Autowired
	private InquiryLinkService inquiryLinkService;
	@Autowired
	private OfferPriceService offerPriceService;


	
	/**
	 * 市场列表
	 */
	@PostMapping("/list")
	public R list(@RequestBody Map<String, Object> params){
		PageUtils page = inquiryService.queryMarketPage(params);

		return R.ok().put("page", page);
	}
	
	/**
	 * 资质详情
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		InquiryEntity entity = inquiryService.getInfo(id);

		if (entity != null) {
			// 获得link信息
			List<InquiryLinkEntity> linkEntities = inquiryLinkService.getLinkList(entity.getId());
			entity.setLinkList(linkEntities);
			// 获得报价list
			List<OfferPriceEntity> offerList = offerPriceService.getListByInquiryId(entity.getId());
			entity.setOfferPriceList(offerList);
		}

        return R.ok().put("info", entity);
	}

}
